import $service from '../../service'
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    clinicSeq: {
      type: String,
      value: ''
    }
  },

  data: {
    recordDetail: {}
  },
  lifetimes: {
    ready() {
      this.getMedicalRecordDetail()
    }
  },
  methods: {
    getMedicalRecordDetail() {
      app.http.getMedicalRecordDetail({
        "clinicSeq": this.properties.clinicSeq,
        "hisMedicalId": this.properties.clinicSeq
      }).then(res => {
        this.data.recordDetail = res.data
        for (let key in this.data.recordDetail) {
          if (!this.data.recordDetail[key] && key != 'medicalInfo') {
            this.data.recordDetail[key] = '--'
          }
          if (key == 'medicalInfo' && this.data.recordDetail['medicalInfo']) {
            this.data.recordDetail['medicalInfo'].forEach(item => {
              for (let i in item) {
                if ((item[i] == '' || item[i] == null) && i != 'prescriptionInfo') {
                  item[i] = '--'
                }
              }
            })
          }
        }
        this.setData({
          recordDetail: this.data.recordDetail
        })
      }).catch(err => {
        console.log(err)
        $service.showToast(err.msg)
      })
    },
    previewImage(e) {
      let {id} = e.currentTarget.dataset
      app.http.getHISPdfOrImg({
        "id": id,
        "type": 2
      }).then(res => {
        wx.previewImage({
          urls: [res.data.url],
        })
      }).catch(err => {
        $service.showToast(err.msg)
      })
    }
  }
})
